<template>
  <div 
    class="chess-piece" 
    :class="{ 
      'can-move': canMove,
      'mini': mini,
      'last-moved': isLastMoved 
    }"
    v-html="pieceIcon"
    @click="handleClick"
  ></div>
</template>

<script setup lang="ts">
import { computed } from 'vue'
import { pieceSvgs } from '../assets/pieces'

interface Props {
  piece: string
  canMove?: boolean
  mini?: boolean
  isLastMoved?: boolean
}

const props = defineProps<Props>()

const emit = defineEmits<{
  (e: 'pieceClick'): void
}>()

const pieceIcon = computed(() => {
  return pieceSvgs[props.piece]
})

const handleClick = () => {
  emit('pieceClick')
}
</script>

<style scoped>
.chess-piece {
  width: 100%;
  height: 100%;
  cursor: pointer;
  position: relative;
}

.chess-piece.mini {
  width: 30px;
  height: 30px;
}

.chess-piece svg {
  width: 100%;
  height: 100%;
}

.can-move {
  background-color: rgba(0, 255, 0, 0.2);
}

.last-moved {
  position: relative;
}

.last-moved::after {
  content: '';
  position: absolute;
  top: -4px;
  left: -4px;
  right: -4px;
  bottom: -4px;
  border: 3px solid #ffd700;
  border-radius: 50%;
  animation: glow 1.5s ease-in-out infinite alternate;
  z-index: 2;
  pointer-events: none;
}

@keyframes glow {
  from {
    box-shadow: 0 0 5px #fff,
                0 0 10px #fff,
                0 0 15px #ffd700,
                0 0 20px #ffd700;
  }
  to {
    box-shadow: 0 0 10px #fff,
                0 0 20px #fff,
                0 0 30px #ffd700,
                0 0 40px #ffd700;
  }
}
</style> 